{{> header}}

<div class="setting main">
    <div class="userBox">
        <p class="title">更新资料</p>
        <form action="/setting" method="post">
            <table width="100%">
                <tr>
                    <td width="80" align="right">用户名：</td>
                    <td><input type="text" value="{{user.name}}" disabled></td>
                </tr>
                <tr>
                    <td align="right">邮箱：</td>
                    <td><input type="text" value="{{user.email}}" disabled></td>
                </tr>
                <tr>
                    <td align="right">个人网站：</td>
                    <td><input type="text" name="web" value="{{user.web}}"></td>
                </tr>
                <tr>
                    <td align="right">所在地点：</td>
                    <td><input type="text" name="address" value="{{user.address}}"></td>
                </tr>
                <tr>
                    <td align="right">微博：</td>
                    <td><input type="text" name="weibo" value="{{user.weibo}}"></td>
                </tr>
                <tr>
                    <td align="right">Github：</td>
                    <td><input type="text" name="github" value="{{user.github}}"></td>
                </tr>
                <tr>
                    <td align="right">简介：</td>
                    <td><textarea name="intro" width="100%" rows="3">{{user.intro}}</textarea></td>
                </tr>
                <tr>
                    <td><input type="hidden" name="action" value="profile"></td>
                    <td><input type="submit" value="保存设置"></td>
                </tr>
            </table>
        </form>
    </div>


    <div class="userBox">
        <p class="title">修改密码</p>
        <form action="/setting" method="post" id="passwordForm">
            <table width="100%">
                <tr>
                    <td width="80" align="right">原始密码：</td>
                    <td><input type="password" name="origin" value="123456"></td>
                </tr>
                <tr>
                    <td width="80" align="right">新密码：</td>
                    <td><input type="password" name="password" value="123456"></td>
                </tr>
                <tr>
                    <td width="80" align="right">确认密码：</td>
                    <td><input type="password" name="repeat" value="123456"></td>
                </tr>
                <tr>
                    <td><input type="hidden" name="action" value="password"></td>
                    <td><input type="submit" value="修改密码"><span id="errorMsg" style="color:#c00;display: none;"></span></td>
                </tr>
            </table>
        </form>
    </div>

</div>

<div class="det">
    {{>loginedSide}}
    {{>friendshipSide}}
</div>

{{#section 'script'}}
<script>
    var limit=[{{passwordCharacterLengthLimit}}];
    $(function(){
        var $form=$('#passwordForm');
        var $error=$('#errorMsg');

        $form.on('submit',function(){
            var origin=$form.find('[name="origin"]').val();
            var password=$form.find('[name="password"]').val();
            var repeat=$form.find('[name="repeat"]').val();
            var errors=[];

            if(!origin)errors.push('原始密码未输入');

            if(!password)errors.push('新密码未输入');
            if(password&&(password.length<limit[0] || password.length>limit[1]))errors.push(['新密码长度非法(',limit[0],'~',limit[1],')'].join(''));

            if(!repeat)errors.push('确认密码未输入');
            if(password&&repeat){
                if(password!==repeat)errors.push('两次密码输入不一致');
            }

            if(errors.length){
                $error.text(errors.join()).show();
                return false;
            }
        });
    });
</script>
{{/section}}